package com.example.androidmainshixun.view;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.androidmainshixun.R;

public class SellerHomepage extends AppCompatActivity implements View.OnClickListener{
    private ImageView miv_first, Mmoment,miv_edit_publish,miv_message,miv_mine;

    private TextView mTextView;
    private MessageFragment messageFragment;
    private MomentFragment moment_fragment;
    private Fragment mContentFragment;
    private FragmentManager mFragmentManager;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seller_homepage);

        miv_first=findViewById(R.id.iv_first);
        Mmoment=findViewById(R.id.moment);
        miv_message=findViewById(R.id.iv_message);
        miv_mine=findViewById(R.id.iv_mine);
        miv_edit_publish=findViewById(R.id.iv_edit_publish);
        mFragmentManager = getSupportFragmentManager();
        showFragment(new SellerHomepageFragement());

        miv_first.setOnClickListener(this);
        Mmoment.setOnClickListener(this);
        miv_edit_publish.setOnClickListener(this);
        miv_mine.setOnClickListener(this);
        miv_message.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id=v.getId();
        if (id== R.id.iv_first){
            showFragment(new SellerHomepageFragement());
        }else if(id == R.id.moment){
            moment_fragment=new MomentFragment();
            showFragment(moment_fragment);
        } else if (id== R.id.iv_edit_publish) {
            Intent intent=new Intent(this, EditActivity.class);
            startActivity(intent);
        } else if (id == R.id.iv_message) {
            messageFragment = new MessageFragment();
            showFragment(messageFragment);
        } else if (id == R.id.iv_mine) {
            Intent intent=new Intent(this, MineActivity.class);
            startActivity(intent);
        }
    }

    public void showFragment(Fragment fragment) {
        if (fragment != null && mContentFragment != fragment) {
            FragmentTransaction transaction=mFragmentManager.beginTransaction();
            if (mContentFragment != null) {
                transaction.hide(mContentFragment);
            }
            transaction.add(R.id.fragment_content_seller,fragment);
            transaction.commit();
            mContentFragment = fragment;
        }
    }
}